package com.manage.platform.controller;

import com.manage.platform.dto.NewCenterDto;
import com.manage.platform.dto.query.NewCenterQuery;
import com.manage.platform.service.impl.NewCenterServiceImpl;
import com.manage.platform.utils.R;
import com.manage.platform.utils.RPage;
import com.manage.platform.vo.NewCenterVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * YWD
 * 2025/9/28
 */
@AllArgsConstructor
@RestController
@RequestMapping("/newCenter")
@Tag(name = "系统设置-新闻管理")
public class NewCenterController {

    private final NewCenterServiceImpl newCenterServiceImpl;

    @PostMapping("/getNewCenterPage")
    @Operation(summary = "查询新闻列表(分页)")
    public R<RPage<List<NewCenterVo>>> getNewCenterPage(@RequestBody NewCenterQuery query) {
        return R.ok(newCenterServiceImpl.getNewCenterPage(query));
    }

    @GetMapping("/getNewCenterDetails/{id}")
    @Operation(summary = "查询新闻详情")
    public R<NewCenterVo> getNewCenterDetails(@Schema(description = "新闻ID") @PathVariable("id") Long id) {
        return R.ok(newCenterServiceImpl.getNewCenterDetails(id));
    }

    @PostMapping("/saveNewCenter")
    @Operation(summary = "添加新闻")
    public R<Boolean> saveNewCenter(@RequestBody NewCenterDto dto) {
        return R.ok(newCenterServiceImpl.saveNewCenter(dto));
    }

    @PutMapping("/updateNewCenter")
    @Operation(summary = "修改新闻")
    public R<Boolean> updateNewCenter(@RequestBody NewCenterDto dto) {
        return R.ok(newCenterServiceImpl.updateNewCenter(dto));
    }

    @DeleteMapping("/deleteNewCenter/{id}")
    @Operation(summary = "删除新闻")
    public R<Boolean> deleteNewCenter(@Schema(description = "ID") @PathVariable("id") Long id) {
        return R.ok(newCenterServiceImpl.deleteNewCenter(id));
    }

    @DeleteMapping("/deleteBatchNewCenter")
    @Operation(summary = "批量删除新闻")
    public R<Boolean> deleteBatchNewCenter(@RequestBody List<Long> ids) {
        return R.ok(newCenterServiceImpl.deleteBatchNewCenter(ids));
    }

}
